// FILE: Chip8ConsoleKeyboard.cpp by Richard Hughes 03/05/2012
//
// DESC: Defines the Win32 console chip 8 keyboard

// INCLUDES
#include <iostream>
#include "Chip8ConsoleKeyboard.h"

// NAMESPACES
using namespace std;

/*************************************************************/
//
// CLASS: Chip8ConsoleKeyboard
//
// DESC: Defines the Win32 based console Chip 8 Keyboard
//
/*************************************************************/

// checks to see if the passed key is down
// the key to check for
// returns true if the key is down, else false
bool Chip8ConsoleKeyboard::IsKeyDown(Chip8Key key)
{
	int k = 0;

	if(key == Chip8Key_0) k = VK_NUMPAD0;
	else if(key == Chip8Key_1) k = VK_NUMPAD1;
	else if(key == Chip8Key_2) k = VK_NUMPAD2;
	else if(key == Chip8Key_3) k = VK_NUMPAD3;
	else if(key == Chip8Key_4) k = VK_NUMPAD4;
	else if(key == Chip8Key_5) k = VK_NUMPAD5;
	else if(key == Chip8Key_6) k = VK_NUMPAD6;
	else if(key == Chip8Key_7) k = VK_NUMPAD7;
	else if(key == Chip8Key_8) k = VK_NUMPAD8;
	else if(key == Chip8Key_9) k = VK_NUMPAD9;
	else if(key == Chip8Key_A) k = VK_F1;
	else if(key == Chip8Key_B) k = VK_F2;
	else if(key == Chip8Key_C) k = VK_F3;
	else if(key == Chip8Key_D) k = VK_F4;
	else if(key == Chip8Key_E) k = VK_F5;
	else if(key == Chip8Key_F) k = VK_F6;
	else if(key == Chip8Key_AttachDebugger) k = VK_F9;
	else if(key == Chip8Key_DetachDebugger) k = VK_F10;
	else if(key == Chip8Key_DebuggerStep) k = VK_F11;

	return GetAsyncKeyState(k) & (0x80 >> 7) == 1;
} // IsKeyDown

// checks to see if the passed key is up
// the key to check for
// returns true if the key is up, else false
bool Chip8ConsoleKeyboard::IsKeyUp(Chip8Key key)
{
	return !this->IsKeyDown(key);
} // IsKeyDown

// EOF: Chip8ConsoleKeyboard.cppVK_F1;